package com.ibeeking.found.open.b.rest.controller.v1;

import com.ibeeking.found.open.api.common.dto.CouponInfoDTO;
import com.ibeeking.found.open.api.common.dto.CouponTypeListDTO;
import com.ibeeking.found.open.api.common.dto.MemberCouponSuperpositionDTO;
import com.ibeeking.found.open.api.common.query.CouponInfoQuery;
import com.ibeeking.found.open.b.rest.service.ICouponService;
import com.ibeeking.found.open.service.common.dto.CouponVerificationChannelListDTO;
import com.ibeeking.found.open.service.common.param.CouponVerificationQRParam;
import com.ibeeking.found.open.service.common.query.CouponLockQuery;
import com.ibeeking.found.open.service.common.query.CouponSuperpositionQuery;
import com.ibeeking.found.open.service.common.query.CouponUnLockQuery;
import com.ibeeking.found.open.service.common.query.CouponVerificationQuery;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @ClassName CouponController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/v1/api/coupon")
public class CouponController {

    @Resource
    private ICouponService couponServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询券类型列表")
    @GetMapping(value = "/couponType")
    public List<CouponTypeListDTO> couponType() {
        return couponServiceImpl.couponType();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询券核销渠道列表")
    @GetMapping(value = "/verificationChannel")
    public List<CouponVerificationChannelListDTO> verificationChannel() {
        return couponServiceImpl.verificationChannel();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "通过券码查询券信息")
    @GetMapping(value = "/info/{couponCode}")
    public CouponInfoDTO queryCouponInfoByCouponCode(@PathVariable @NotNull(message = "券码不能为空") Long couponCode) {
        return couponServiceImpl.queryCouponInfoByCouponCode(couponCode);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "锁定优惠券")
    @PostMapping(value = "/lock")
    public Boolean couponLock(@RequestBody @Validated CouponLockQuery query) {
        return couponServiceImpl.couponLock(query);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "释放优惠券")
    @PostMapping(value = "/unLock")
    public Boolean couponUnLock(@RequestBody @Validated CouponUnLockQuery query) {
        return couponServiceImpl.couponUnLock(query);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "核销优惠券")
    @PostMapping(value = "/verification")
    public Boolean couponVerification(@RequestBody @Validated CouponVerificationQuery query) {
        return couponServiceImpl.couponVerification(query);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "核销优惠券")
    @PostMapping(value = "/verificationCoupon")
    public Boolean verificationCouponByQR(@RequestBody @Validated CouponVerificationQRParam param) {
        return couponServiceImpl.verificationCouponByQR(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "券详情查询")
    @PostMapping(value = "/queryCouponInfo")
    public CouponInfoDTO queryCouponInfo(@RequestBody @Validated CouponInfoQuery query) {
        return couponServiceImpl.queryCouponInfo(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "会员优惠券可用叠加查询校验")
    @PostMapping(value = "/superposition")
    public MemberCouponSuperpositionDTO superposition(@RequestBody @Validated CouponSuperpositionQuery query) {
        return couponServiceImpl.superposition(query);
    }
}
